<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" src="/js/jquery-2.2.4.js"></script>

<body>

<input type="text" id="depId" placeholder="请输入要查询的部门Id" />
<input type="text" id="depName" placeholder="请输入要查询的部门部门" />
<button id="chaxu">查询</button>

<table align="center" width="80%">
    <tr>
        <th>编号</th>
        <th>名称</th>
        <th>图片</th>
        <th>操作</th>
    </tr>


    <tr th:each="d:${list}">
        <td th:text="${d.depId}"></td>
        <td th:text="${d.depName}"></td>
        <td th:text="${d.image}"></td>
        <td> <button th:onclick="'del('+${d.depId}+')'">删除</button></td>
    </tr>
</table>

</body>
<script>

    function del(id) {
        $.ajax({
            url:"/delByIdDep",
            data:{id:id},
            success:function (res) {
                alert(res)
                if (res==2){
                    alert("删除成功");
                } else if (res==0) {
                    alert("请选择部门进行删除")
                }else{
                    alert("删除失败")

                }
            },
            error:function (res) {
                alert("网络错误");
            }
        })
        alert(id)
    }

    $("#chaxu").click(function () {
        var depId=$("#depId").val();
        var depName=$("#depName").val();
        $.ajax({
            method:"get",
            url:"/searchDep",
            data:{
                depId:depId,
                depName:depName
            }

        })

    })
</script>
</html>